﻿
ptkc.sum = function (arg1, arg2) {
    this.arg1 = arg1 == '' ? 0 : parseFloat(arg1)          
    this.arg2 = arg2 == '' ? 0 : parseFloat(arg2)
    return this
}
ptkc.sum.prototype = {
    tofide: function (str) {
        if (String(str).indexOf(".") > -1) {
            if (str.toString().split(".")[1].length > 2) {
                return str.toFixed(2)
            } else {
                return str
            }
        } else {
            return str
        }
    },
    accAdd: function () {
        var r1, r2, m
        try {
            r1 = this.arg1.toString().split(".")[1].length
        } catch (e) {
            r1 = 0
        }
        try {
            r2 = this.arg2.toString().split(".")[1].length
        } catch (e) {
            r2 = 0
        }
        m = Math.pow(10, Math.max(r1, r2))
        return this.tofide((this.arg1 * m + this.arg2 * m) / m)
    },
    accSub: function () {
        var r1, r2, m
        try {
            r1 = this.arg1.toString().split(".")[1].length
        } catch (e) {
            r1 = 0
        }
        try {
            r2 = this.arg2.toString().split(".")[1].length
        } catch (e) {
            r2 = 0
        }
        m = Math.pow(10, Math.max(r1, r2))
        return this.tofide((this.arg1 * m - this.arg2 * m) / m)
    },
    accMul: function () {
        var m = 0, s1 = this.arg1.toString(), s2 = this.arg2.toString()
        try {
            m += s1.split(".")[1].length
        } catch (e) {
        }
        try {
            m += s2.split(".")[1].length
        } catch (e) {
        }
        return this.tofide(Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m))
    },
    accDiv: function () {
        var t1 = 0, t2 = 0, r1, r2
        try {
            t1 = this.arg1.toString().split(".")[1].length
        } catch (e) {
        }
        try {
            t2 = this.arg2.toString().split(".")[1].length
        } catch (e) {
        }
        with (Math) {
            r1 = Number(this.arg1.toString().replace(".", ""))
            r2 = Number(this.arg2.toString().replace(".", ""))
            return this.tofide((r1 / r2) * pow(10, t2 - t1))
        }
    }
}
